<#assign ctx=request.contextPath />

<!-- toolbar-->
<div id="wxAccounts_tb" style="padding:5px;height:auto">
    <div style="margin-bottom:5px">
        <a href="#" class="easyui-linkbutton" iconCls="icon-plus" plain="true" id="wxAccounts_add">添加</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="wxAccounts_edit">修改</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
           id="wxAccounts_delete">删除</a>
    </div>
</div>

<!--datagrid-->
<table class="easyui-datagrid" id="wxAccounts_datagrid" toolbar="#wxAccounts_tb"
       data-options="url:'${ctx}/wxAccounts/datagrid.json',rownumbers:true,singleSelect:true,fitColumns:true,method:'get',striped:true,pagination:true,pageSize:20,pageList:[20,30,40,50,100]">
    <thead>
    <tr>
        <th field="name" width="15%">公众号名称</th>
        <th field="token" width="15%">微信Token</th>
        <th field="wxappId" width="20%">微信appId</th>
        <th field="appsecret" width="20%">微信appsecret</th>
        <th field="address" width="20%">微信应用地址</th>
        <th field="ack" width="20%">ack</th>
        <th field="created" width="9%">创建时间</th>
        <th field="fileName" width="15%">文件名</th>
        <th field="fileContent" width="25%">文件内容</th>
    </tr>
    </thead>
</table>


<div id="wxAccounts_win_add" class="easyui-window"
     data-options="closed:true,title:'微信公众号',modal:true,collapsible:false,minimizable:false,maximizable:false"
     style="width:400px;height:500px;padding:5px;">
    <form id="wxAccounts_form_add" method="post">
        <div class="form-control">
            <label for="name">公众号名称:</label>
            <input class="easyui-validatebox" type="text" name="name" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信Token:</label>
            <input class="easyui-validatebox" type="text" name="token" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信appId:</label>
            <input class="easyui-validatebox" type="text" name="wxappId" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信appsecret:</label>
            <input class="easyui-validatebox" type="text" name="appsecret" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">ack:</label>
            <input class="easyui-validatebox" type="text" name="ack"/>
        </div>
        <div class="form-control">
            <label for="name">微信应用:</label>
            <select class="easyui-combobox"
                    data-options="url:'${ctx}/wxApplications/findAll.json',valueField:'id',textField:'address',method:'GET'"
                    name="applicationId" style="height:30px;width:230px;" required="required">

            </select>
        </div>
        <div class="form-control">
            <label for="name">文件名:</label>
            <input style="width:50%;height:15px;" class="easyui-validatebox" type="text" name="fileName" placeholder="格式如：MP_xxxxx.txt"/>
        </div>
        <div class="form-control">
            <label for="name" style="float:left;">文件内容:</label>
            <textarea class="form-control"  rows="4" name="fileContent"/>
        </div>
        <div class="form-control" style="text-align: center;">
            <a id="wxAccount_add_save" href="#" class="easyui-linkbutton"
               data-options="iconCls:'icon-save'">保存</a>
        </div>
    </form>
</div>

<div id="wxAccounts_win_edit" class="easyui-window"
     data-options="closed:true,title:'微信公众号',modal:true,collapsible:false,minimizable:false,maximizable:false"
     style="width:400px;height:500px;padding:5px;">
    <form id="wxAccounts_form_edit" method="patch">
        <div class="form-control">
            <label for="name">公众号名称:</label>
            <input class="easyui-validatebox" type="text" name="name" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信Token:</label>
            <input class="easyui-validatebox" type="text" name="token" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信appId:</label>
            <input class="easyui-validatebox" type="text" name="wxappId" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">微信appsecret:</label>
            <input class="easyui-validatebox" type="text" name="appsecret" required="required"/>
        </div>
        <div class="form-control">
            <label for="name">ack:</label>
            <input class="easyui-validatebox" type="text" name="ack"/>
        </div>
        <div class="form-control">
            <label for="name">微信应用:</label>
            <select class="easyui-combobox"
                    data-options="url:'${ctx}/wxApplications/findAll.json',valueField:'id',textField:'address',method:'GET'"
                    name="applicationId" style="height:30px;width:230px;" required="required">
            </select>
        </div>
        <div class="form-control">
            <label for="name">文件名:</label>
            <input style="width:50%;height:15px;" class="easyui-validatebox" type="text" name="fileName" placeholder="格式如：MP_xxxxx.txt"/>
        </div>
        <div class="form-control">
            <label for="name" style="float: left;">文件内容:</label>
            <textarea class="form-control"  rows="4" name="fileContent"></textarea>
        </div>
        <div class="form-control" style="text-align: center;">
            <a id="wxAccount_edit_save" href="#" class="easyui-linkbutton"
               data-options="iconCls:'icon-save'">保存</a>
        </div>
    </form>
</div>

<script type="text/javascript">
    //系统配置
    $("#wxAccounts_add").click(function () {
        $("#wxAccounts_win_add").window('open');
    });

    $("#wxAccounts_edit").click(function () {

        var selection = $("#wxAccounts_datagrid").datagrid('getSelected');
        if (null == selection) {
            $.messager.show({
                                msg: "请选择要编辑的数据",
                                title: "确认"
                            });
            return;
        }

        $("#wxAccounts_form_edit").form('load', '${ctx}/wxAccounts/' + selection.id + ".json");
        $("#wxAccounts_win_edit").window('open');

    });

    $("#wxAccounts_delete").click(function () {

        var selection = $("#wxAccounts_datagrid").datagrid('getSelected');

        if (null == selection) {
            $.messager.show({
                                msg: "请选择要删除的数据",
                                title: "确认"
                            });

            return;
        }

        core.func.del('${ctx}/wxAccounts/' + selection.id + '.json', function (data) {
            if (data.status == 0) {
                $.messager.show({
                                    msg: "删除成功",
                                    title: "提示"
                                });
                $("#wxAccounts_datagrid").datagrid('reload');
            } else {
                $.messager.show({
                                    msg: "删除失败",
                                    title: "失败"
                                });
            }
        });

    });

    $("#wxAccount_add_save").click(function () {

        if ($("#wxAccounts_form_add").form('validate')) {

            var params = $("#wxAccounts_form_add").serialize();

            core.func.post('${ctx}/wxAccounts.json', params, function (data) {
                if (data.status == 0) {
                    $("#wxAccounts_form_add").form('clear');
                    $("#wxAccounts_win_add").window('close');
                    $("#wxAccounts_datagrid").datagrid('load');
                    $.messager.show({
                                        msg: "微信公众号信息保存成功",
                                        title: "成功",
                                        timeout: 1000
                                    });
                } else if (data.status == -1) {
                    $.messager.show({
                                        msg: "公众号名称或文件名已经存在",
                                        title: "失败"
                                    });
                } else {
                    $.messager.show({
                                        msg: "微信公众号信息保存失败",
                                        title: "失败"
                                    });
                }
            });

        }

    });

    $("#wxAccount_edit_save").click(function () {

        var selection = $("#wxAccounts_datagrid").datagrid('getSelected');

        if ($("#wxAccounts_form_edit").form('validate')) {

            var params = $("#wxAccounts_form_edit").serialize();

            core.func.patch('${ctx}/wxAccounts/' + selection.id + '.json', params, function (data) {
                if (data.status == 0) {
                    $("#wxAccounts_form_edit").form('clear');
                    $("#wxAccounts_win_edit").window('close');
                    $("#wxAccounts_datagrid").datagrid('reload');
                    $.messager.show({
                                        msg: "微信公众号信息保存成功",
                                        title: "成功",
                                        timeout: 1000
                                    });
                } else if (data.status == -1) {
                    $.messager.show({
                                        msg: "微信公众号不存在",
                                        title: "失败"
                                    });
                } else if (data.status == -2) {
                    $.messager.show({
                                        msg: "微信公众号或文件名名称重复",
                                        title: "失败"
                                    });
                } else {
                    $.messager.show({
                                        msg: "微信公众号信息保存失败",
                                        title: "失败"
                                    });
                }
            });
        }

    });

</script>
